var net = require('net');
var fs = require('fs')
var readline = require('readline');
var path = __dirname + '/../base';

var client = new net.Socket();
client.connect(8001, '127.0.0.1', function() {
    var lines = []
    var myInterface = readline.createInterface({
        input: fs.createReadStream(path + '/' + "7_188001.txt")
    });
    myInterface.on('line', function (line) {
        var index = line.split(',');
        lines.push(line)
    });
    myInterface.on('close', function () {
        var i = 0

        var setTime = setInterval(function () {
            client.write(lines[i])
            i++;
            if (i === lines.length) {
                clearInterval(setTime)
            }
        }, 1000)
    })
    // client.write('Hello, server! Love, Client.');
});

client.on('data', function(data) {
    console.log('Received: ' + data);
    // client.destroy();
});

client.on('close', function() {
    console.log('Connection closed');
});